package com.it.product.Service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.product.Entity.feginEntity;
import com.it.product.Mapper.feignMapper;
import com.it.product.Service.feginService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service("feginService")
public class feginServiceImpl extends ServiceImpl<feignMapper, feginEntity> implements feginService {



    @Override
    public List<feginEntity> theMethod() {
        //当存在这个时间段的时候，处于秒杀状态    开始时间为 当前时间    结束时间为 当前时间+2
        List<feginEntity> list = this.baseMapper.selectList(new QueryWrapper<feginEntity>()
                .between("start_time", startTime(), endTime()));

        //放入你关于产品的业务代码

        return list;
    }

    /**
     * 当前时间
     * @return
     */
    private String startTime() {
        LocalDate now = LocalDate.now();
        LocalTime min = LocalTime.MIN;
        LocalDateTime start = LocalDateTime.of(now, min);

        //格式化时间
        String startFormat = start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return startFormat;
    }

    /**
     * 结束时间
     * @return
     */
    private String endTime() {
        LocalDate now = LocalDate.now();
        LocalDate plus = now.plusDays(2);
        LocalTime max = LocalTime.MAX;
        LocalDateTime end = LocalDateTime.of(plus, max);

        //格式化时间
        String endFormat = end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return endFormat;
    }



}
